const useDictUtilsStore = defineStore('dictUtils', () => {
  const mapVOS = ref<{ [K: string]: Record<string, string> }>({});

  const getMapVO = (_key: string) => {
    return mapVOS.value[_key] || {};
  };

  const setMapVo = (_key: string, values: any[]) => {
    if (Array.isArray(values)) {
      mapVOS.value[_key] = values.reduce((cur, next) => ((cur[next.value] = next.label), cur), {});
    }
  };

  const getlabel = (_key: string, value: string) => {
    return getMapVO(_key)?.[value] || value;
  };

  return {
    mapVOS,
    getMapVO,
    setMapVo,
    getlabel
  };
});

export default useDictUtilsStore;
